import { EditableCallbackParams } from '@ag-grid-community/core'

import { TCol } from '@oBiz/TrackManage/List/interface'
import { TOperationType } from '../interface'

export const isFirstEditable = (params: EditableCallbackParams) => {
  const { data } = params
  return data?.transportType === 1
}

export const updateServiceLevelColumnDefs = [
  {
    headerName: '运单编号',
    field: 'waybillNo',
    width: 140,
    cellClass: 'no-padding',
  } satisfies TCol<'waybillNo'>,
  {
    headerName: 'FBA ID',
    field: 'fbaId',
    width: 140,
  } satisfies TCol<'fbaId'>,
  {
    headerName: '物流渠道',
    field: 'logisticsChannelName',
    width: 140,
  } satisfies TCol<'logisticsChannelName'>,
  {
    headerName: '渠道单号',
    field: 'logisticsChannelTrackingNumber',
    width: 120,
  } satisfies TCol<'logisticsChannelTrackingNumber'>,
  {
    headerName: '服务等级',
    field: 'logisticsChannelServiceLevel',
    width: 230,
    cellClass: 'no-padding',
  } satisfies TCol<'logisticsChannelServiceLevel'>,
  {
    headerName: '最短时效',
    field: 'logisticsChannelServiceTransitMin',
    width: 140,
    cellClass: 'no-padding',
  } satisfies TCol<'logisticsChannelServiceTransitMin'>,
  {
    headerName: '最长时效',
    field: 'logisticsChannelServiceTransitMax',
    width: 140,
    cellClass: 'no-padding',
  } satisfies TCol<'logisticsChannelServiceTransitMax'>,
  {
    headerName: '结果',
    field: 'result',
    width: 100,
  } as TCol<'result'>,
]

export const updateFirstLineColumnDefs = [
  {
    headerName: '运单编号',
    field: 'waybillNo',
    width: 140,
    cellClass: 'no-padding',
  } satisfies TCol<'waybillNo'>,
  {
    headerName: 'FBA ID',
    field: 'fbaId',
    width: 120,
  } satisfies TCol<'fbaId'>,
  {
    headerName: '物流渠道',
    field: 'logisticsChannelName',
    width: 120,
  } satisfies TCol<'logisticsChannelName'>,
  {
    headerName: '渠道单号',
    field: 'logisticsChannelTrackingNumber',
  } satisfies TCol<'logisticsChannelTrackingNumber'>,
  {
    headerName: '头运输方式',
    field: 'transportType',
    width: 140,
  } satisfies TCol<'transportType'>,
  {
    headerName: '承运商',
    field: 'carrier',
    cellClass: 'no-padding',
    width: 120,
  } satisfies TCol<'carrier'>,
  {
    headerName: '船名',
    field: 'vesselName',
    cellClass: 'no-padding',
    width: 120,
  } satisfies TCol<'vesselName'>,
  {
    headerName: '航次',
    field: 'voyageNumber',
    cellClass: 'no-padding',
    width: 120,
  } satisfies TCol<'voyageNumber'>,
  {
    headerName: '柜号',
    field: 'containerNumber',
    cellClass: 'no-padding',
    width: 120,
  } satisfies TCol<'containerNumber'>,
  {
    headerName: '起运港',
    field: 'departureLocationId',
    cellClass: 'no-padding',
    width: 120,
  } satisfies TCol<'departureLocationId'>,
  {
    headerName: 'ETD',
    field: 'etd',
    cellClass: 'no-padding',
    width: 120,
  } satisfies TCol<'etd'>,
  {
    headerName: '目的港',
    field: 'destinationLocationId',
    cellClass: 'no-padding',
    width: 120,
  } satisfies TCol<'destinationLocationId'>,
  {
    headerName: 'ETA',
    field: 'eta',
    cellClass: 'no-padding',
    width: 120,
  } satisfies TCol<'eta'>,
  {
    headerName: '航行天数',
    field: 'transitDays',
    width: 120,
  } satisfies TCol<'transitDays'>,
  {
    headerName: '结果',
    field: 'result',
    width: 120,
  } satisfies TCol<'result'>,
]

export const updateTailLinesColumnDefs = [
  {
    headerName: '运单编号',
    field: 'waybillNo',
    width: 120,
  } satisfies TCol<'waybillNo'>,
  {
    headerName: 'FBA ID',
    field: 'fbaId',
    width: 120,
  } satisfies TCol<'fbaId'>,
  {
    headerName: '物流渠道',
    field: 'logisticsChannelName',
    width: 120,
  } satisfies TCol<'logisticsChannelName'>,
  {
    headerName: '渠道单号',
    field: 'logisticsChannelTrackingNumber',
    width: 120,
  } satisfies TCol<'logisticsChannelTrackingNumber'>,
  {
    headerName: '尾程运输方式',
    field: 'lastMileTransportType',
    editable: true,
    width: 200,
    cellClass: 'no-padding',
  } satisfies TCol<'lastMileTransportType'>,
  {
    headerName: '尾程服务商',
    field: 'lastMileCarrier',
    editable: true,
    width: 150,
    cellClass: 'no-padding',
  } satisfies TCol<'lastMileCarrier'>,
  {
    headerName: 'BOL',
    field: 'lastMileWaybillNo',
    editable: true,
    cellClass: 'no-padding',
    width: 120,
  } satisfies TCol<'lastMileWaybillNo'>,
  {
    headerName: '结果',
    field: 'result',
  } satisfies TCol<'result'>,
]

export const getTableColumnDefs = (operationType: TOperationType) => {
  switch (operationType) {
    case 'updateServiceLevel':
      return updateServiceLevelColumnDefs
    case 'updateFirstLine':
      return updateFirstLineColumnDefs
    case 'updateTailLines':
      return updateTailLinesColumnDefs
  }
}
